home *** CD-ROM | disk | FTP | other *** search
/ Champak Vol A-4 / (Vol A-4) Vol. A4.iso / Games / the-kitchen-of-doom.swf / scripts / frame_31 / DoAction.as
Text File  |  2008-03-14  |  28KB  |  842 lines

  1. function getAverageFramerate()
  2. {
  3.    if(frameCount++ >= numberOfFrames)
  4.    {
  5.       var _loc2_ = getTimer() - timeStamp;
  6.       var _loc1_ = frameCount / _loc2_ * 1000;
  7.       timeStamp = getTimer();
  8.       frameCount = 0;
  9.       if(numberOfFrames != 1)
  10.       {
  11.          sendAverageFramerate(_loc1_);
  12.       }
  13.       numberOfFrames = 200;
  14.    }
  15. }
  16. function sendAverageFramerate(fps)
  17. {
  18.    var _loc1_ = Math.ceil(fps);
  19.    StatsTrackerInst.SendFrameRateInfo(3,_loc1_);
  20.    fpsInfoSent = true;
  21. }
  22. function getKeyPresses()
  23. {
  24.    if(demo.length <= 600)
  25.    {
  26.       demoMoving.push(keysRecorded);
  27.       demoShooting.push(shotRecorded);
  28.       keysRecorded = 0;
  29.       shotRecorded = 0;
  30.       if(demoMoving.length == 600)
  31.       {
  32.          trace(demoMoving);
  33.          trace(demoShooting);
  34.       }
  35.    }
  36. }
  37. function nextKeyPress()
  38. {
  39.    demoKey++;
  40. }
  41. function spawnEnemy(spawnPoint)
  42. {
  43.    var _loc2_ = spawnPoint;
  44.    _global.sfxSpawn.start();
  45.    enemiesActive.push(enemiesFree.shift());
  46.    var _loc1_ = enemiesActive.length - 1;
  47.    levelObjectsInst[enemiesActive[_loc1_]].drop = 10;
  48.    levelObjectsInst[enemiesActive[_loc1_]].active = true;
  49.    levelObjectsInst[enemiesActive[_loc1_]].death = false;
  50.    levelObjectsInst[enemiesActive[_loc1_]].lives = 3;
  51.    levelObjectsInst[enemiesActive[_loc1_]].state = 1;
  52.    levelObjectsInst[enemiesActive[_loc1_]]._visible = true;
  53.    levelObjectsInst[enemiesActive[_loc1_]]._alpha = 100;
  54.    levelObjectsInst[enemiesActive[_loc1_]]._x = _loc2_._x;
  55.    levelObjectsInst[enemiesActive[_loc1_]]._y = _loc2_._y;
  56.    if(_loc2_.spawnDir > 0)
  57.    {
  58.       levelObjectsInst[enemiesActive[_loc1_]].dir = 1;
  59.       levelObjectsInst[enemiesActive[_loc1_]].bacteriaAnimsInst._xscale = -100;
  60.    }
  61.    else
  62.    {
  63.       levelObjectsInst[enemiesActive[_loc1_]].dir = 0;
  64.       levelObjectsInst[enemiesActive[_loc1_]].bacteriaAnimsInst._xscale = 100;
  65.    }
  66.    levelObjectsInst[enemiesActive[_loc1_]].point1 = _loc2_.point1;
  67.    levelObjectsInst[enemiesActive[_loc1_]].point2 = _loc2_.point2;
  68.    levelObjectsInst[enemiesActive[_loc1_]].spawn = _loc2_._name;
  69. }
  70. function removeEnemy(enemy)
  71. {
  72.    var _loc1_ = 0;
  73.    while(_loc1_ < enemiesActive.length)
  74.    {
  75.       if(enemiesActive[_loc1_] == enemy)
  76.       {
  77.          levelObjectsInst[enemiesActive[_loc1_]].state = 0;
  78.          levelObjectsInst[enemiesActive[_loc1_]].bacteriaAnimsInst.SetAnimation(1);
  79.          levelObjectsInst[enemiesActive[_loc1_]].death = false;
  80.          levelObjectsInst[enemiesActive[_loc1_]]._xscale = 100;
  81.          levelObjectsInst[enemiesActive[_loc1_]]._yscale = 100;
  82.          levelObjectsInst[enemiesActive[_loc1_]]._rotation = 0;
  83.          var _loc2_ = {rb:0,bb:0,gb:0};
  84.          levelObjectsInst[enemiesActive[_loc1_]].red = false;
  85.          levelObjectsInst[enemiesActive[_loc1_]].colour.setTransform(_loc2_);
  86.          levelObjectsInst[enemiesActive[_loc1_]].active = false;
  87.          levelObjectsInst[enemiesActive[_loc1_]]._visible = false;
  88.          var _loc3_ = levelObjectsInst[enemiesActive[_loc1_]].spawn;
  89.          levelObjectsInst[_loc3_].currEnemies--;
  90.          enemiesFree.push(enemiesActive.splice(_loc1_,1)[0]);
  91.          break;
  92.       }
  93.       _loc1_ = _loc1_ + 1;
  94.    }
  95. }
  96. function enemyDeathAnim(enemy)
  97. {
  98.    var _loc1_ = enemy;
  99.    levelObjectsInst[enemiesActive[_loc1_]].drop -= 2;
  100.    levelObjectsInst[enemiesActive[_loc1_]].state = 0;
  101.    levelObjectsInst[enemiesActive[_loc1_]].bacteriaAnimsInst.SetAnimation(1);
  102.    levelObjectsInst[enemiesActive[_loc1_]]._y -= levelObjectsInst[enemiesActive[_loc1_]].drop;
  103.    levelObjectsInst[enemiesActive[_loc1_]]._rotation = 180;
  104.    if(!stageBoxInst.hitTest(levelObjectsInst[enemiesActive[_loc1_]]))
  105.    {
  106.       removeEnemy(enemiesActive[_loc1_]);
  107.    }
  108. }
  109. function bulletCollisionCheck(enemy)
  110. {
  111.    var _loc2_ = enemy;
  112.    var _loc3_ = this;
  113.    var _loc1_ = 0;
  114.    while(_loc1_ < bulletsActive.length)
  115.    {
  116.       if(levelObjectsInst[enemiesActive[_loc2_]].hitBoxInst.hitTest(_loc3_[bulletsActive[_loc1_]].bulletInst.hitBoxInst))
  117.       {
  118.          if(levelObjectsInst[enemiesActive[_loc2_]].state != 3 && !_loc3_[bulletsActive[_loc1_]].isNew && levelObjectsInst[enemiesActive[_loc2_]].active)
  119.          {
  120.             enemyHit(_loc2_);
  121.             removeBullet(_loc1_);
  122.          }
  123.       }
  124.       _loc1_ = _loc1_ + 1;
  125.    }
  126. }
  127. function foodCollisionCheck(enemy)
  128. {
  129.    var _loc2_ = enemy;
  130.    var _loc1_ = 0;
  131.    while(_loc1_ < FOOD_ITEMS)
  132.    {
  133.       if(levelObjectsInst["food" + _loc1_]._visible)
  134.       {
  135.          if(levelObjectsInst[enemiesActive[_loc2_]].hitBoxInst.hitTest(levelObjectsInst["food" + _loc1_].hitBoxInst))
  136.          {
  137.             levelObjectsInst["food" + _loc1_].value = 0;
  138.             levelObjectsInst["food" + _loc1_].play();
  139.          }
  140.       }
  141.       _loc1_ = _loc1_ + 1;
  142.    }
  143. }
  144. function spudCollisionCheck(enemy)
  145. {
  146.    var _loc1_ = enemy;
  147.    if(levelObjectsInst[enemiesActive[_loc1_]].hitBoxInst.hitTest(playerInst.hitBoxInst))
  148.    {
  149.       if(levelObjectsInst[enemiesActive[_loc1_]].state != 3 && playerInvincible == false)
  150.       {
  151.          if(levelObjectsInst[enemiesActive[_loc1_]].active)
  152.          {
  153.             spudHit();
  154.          }
  155.       }
  156.    }
  157. }
  158. function enemyHit(enemy)
  159. {
  160.    var _loc1_ = enemy;
  161.    switch(gunType)
  162.    {
  163.       case "ice":
  164.          levelObjectsInst[enemiesActive[_loc1_]].enemyFrozen();
  165.          _global.sfxFreeze.start();
  166.          break;
  167.       case "spray":
  168.          levelObjectsInst[enemiesActive[_loc1_]].enemySprayed();
  169.          levelObjectsInst[enemiesActive[_loc1_]].lives -= 1.5;
  170.          break;
  171.       case "fire":
  172.          levelObjectsInst[enemiesActive[_loc1_]].enemyBurnt();
  173.          levelObjectsInst[enemiesActive[_loc1_]].lives--;
  174.    }
  175.    if(levelObjectsInst[enemiesActive[_loc1_]].lives <= 0)
  176.    {
  177.       levelObjectsInst[enemiesActive[_loc1_]].death = true;
  178.       levelObjectsInst[enemiesActive[_loc1_]].active = false;
  179.    }
  180. }
  181. function updateEnemies()
  182. {
  183.    var _loc1_ = 0;
  184.    while(_loc1_ < enemiesActive.length)
  185.    {
  186.       bulletCollisionCheck(_loc1_);
  187.       spudCollisionCheck(_loc1_);
  188.       foodCollisionCheck(_loc1_);
  189.       levelObjectsInst[enemiesActive[_loc1_]].updateEnemy();
  190.       if(levelObjectsInst[enemiesActive[_loc1_]].death)
  191.       {
  192.          enemyDeathAnim(_loc1_);
  193.       }
  194.       _loc1_ = _loc1_ + 1;
  195.    }
  196. }
  197. function updateSpawnPoints()
  198. {
  199.    var _loc3_ = this;
  200.    var _loc1_ = 1;
  201.    while(_loc1_ < SPAWN_POINTS + 1)
  202.    {
  203.       if(levelObjectsInst["spawnPoint" + _loc1_].lives == 1)
  204.       {
  205.          levelObjectsInst["spawnPoint" + _loc1_].gotoAndPlay("destroy");
  206.          levelObjectsInst["spawnPoint" + _loc1_].lives--;
  207.       }
  208.       if(levelObjectsInst["spawnPoint" + _loc1_].lives != 0)
  209.       {
  210.          var _loc2_ = 0;
  211.          while(_loc2_ < bulletsActive.length)
  212.          {
  213.             if(levelObjectsInst["spawnPoint" + _loc1_].hitBoxInst.hitTest(_loc3_[bulletsActive[_loc2_]].bulletInst.hitBoxInst) && levelObjectsInst["spawnPoint" + _loc1_].active && !_loc3_[bulletsActive[_loc2_]].isNew)
  214.             {
  215.                if(gunType == "ice")
  216.                {
  217.                   _global.sfxFreeze.start();
  218.                   levelObjectsInst["spawnPoint" + _loc1_].gotoAndStop("freeze");
  219.                   levelObjectsInst["spawnPoint" + _loc1_].active = false;
  220.                   levelObjectsInst["spawnPoint" + _loc1_].interval = TimerInst.getTime();
  221.                }
  222.                else
  223.                {
  224.                   levelObjectsInst["spawnPoint" + _loc1_].lives--;
  225.                }
  226.                removeBullet(_loc2_);
  227.             }
  228.             _loc2_ = _loc2_ + 1;
  229.          }
  230.          if(levelObjectsInst["spawnPoint" + _loc1_].spawns != 0)
  231.          {
  232.             var wait = levelObjectsInst["spawnPoint" + _loc1_].spawnInterval;
  233.          }
  234.          else
  235.          {
  236.             var wait = levelObjectsInst["spawnPoint" + _loc1_].spawnWait;
  237.          }
  238.          if(TimerInst.getTime() - levelObjectsInst["spawnPoint" + _loc1_].interval > wait)
  239.          {
  240.             levelObjectsInst["spawnPoint" + _loc1_].interval = TimerInst.getTime();
  241.             levelObjectsInst["spawnPoint" + _loc1_]._alpha = 100;
  242.             if(levelObjectsInst["spawnPoint" + _loc1_].currEnemies < levelObjectsInst["spawnPoint" + _loc1_].maxEnemies)
  243.             {
  244.                if(levelObjectsInst["spawnPoint" + _loc1_].active == true)
  245.                {
  246.                   if(!levelObjectsInst["spawnPoint" + _loc1_].hitBoxInst.hitTest(playerInst.hitBoxInst))
  247.                   {
  248.                      spawnEnemy(levelObjectsInst["spawnPoint" + _loc1_]);
  249.                      levelObjectsInst["spawnPoint" + _loc1_].currEnemies = levelObjectsInst["spawnPoint" + _loc1_].currEnemies + 1;
  250.                      levelObjectsInst["spawnPoint" + _loc1_].spawns = levelObjectsInst["spawnPoint" + _loc1_].spawns + 1;
  251.                   }
  252.                }
  253.             }
  254.             if(!levelObjectsInst["spawnPoint" + _loc1_].active)
  255.             {
  256.                if(stageBoxInst.hitTest(levelObjectsInst["spawnPoint" + _loc1_]))
  257.                {
  258.                   _global.sfxUnFreeze.start();
  259.                }
  260.                levelObjectsInst["spawnPoint" + _loc1_].gotoAndPlay(1);
  261.                levelObjectsInst["spawnPoint" + _loc1_].active = true;
  262.             }
  263.          }
  264.          else if(levelObjectsInst["spawnPoint" + _loc1_]._currentframe == 65)
  265.          {
  266.             if(TimerInst.getTime() - levelObjectsInst["spawnPoint" + _loc1_].interval > wait - 2000)
  267.             {
  268.                if(levelObjectsInst["spawnPoint" + _loc1_]._alpha == 100)
  269.                {
  270.                   levelObjectsInst["spawnPoint" + _loc1_]._alpha = 25;
  271.                }
  272.                else
  273.                {
  274.                   levelObjectsInst["spawnPoint" + _loc1_]._alpha = 100;
  275.                }
  276.             }
  277.          }
  278.       }
  279.       _loc1_ = _loc1_ + 1;
  280.    }
  281. }
  282. function resetSpawnPoints()
  283. {
  284.    var _loc1_ = 1;
  285.    while(_loc1_ < SPAWN_POINTS + 1)
  286.    {
  287.       levelObjectsInst["spawnPoint" + _loc1_].gotoAndPlay(1);
  288.       levelObjectsInst["spawnPoint" + _loc1_].lives = 4;
  289.       levelObjectsInst["spawnPoint" + _loc1_].spawns = 0;
  290.       levelObjectsInst["spawnPoint" + _loc1_]._xscale = 100;
  291.       levelObjectsInst["spawnPoint" + _loc1_]._yscale = 100;
  292.       _loc1_ = _loc1_ + 1;
  293.    }
  294. }
  295. function spudHit()
  296. {
  297.    if(playerInst.playerActive)
  298.    {
  299.       _global.sfxHurt.start();
  300.       HUDBoxInst.livesInst.play();
  301.       lives--;
  302.    }
  303.    if(lives > 0)
  304.    {
  305.       flashTime = TimerInst.getTime();
  306.       playerInvincible = true;
  307.    }
  308.    else
  309.    {
  310.       playerInst.playerActive = false;
  311.    }
  312. }
  313. function checkFoodCollisions()
  314. {
  315.    var _loc2_ = _global;
  316.    var _loc1_ = 0;
  317.    while(_loc1_ < FOOD_ITEMS)
  318.    {
  319.       if(levelObjectsInst["food" + _loc1_]._visible && playerInst.playerActive)
  320.       {
  321.          if(playerInst.hitBoxInst.hitTest(levelObjectsInst["food" + _loc1_].hitBoxInst))
  322.          {
  323.             foodCollected++;
  324.             foodSaved += levelObjectsInst["food" + _loc1_].value;
  325.             if(levelObjectsInst["food" + _loc1_].value == 1)
  326.             {
  327.                _loc2_.sfxCollectGood.start();
  328.             }
  329.             else
  330.             {
  331.                _loc2_.sfxCollectBad.start();
  332.             }
  333.             levelObjectsInst["food" + _loc1_]._visible = false;
  334.          }
  335.       }
  336.       _loc1_ = _loc1_ + 1;
  337.    }
  338. }
  339. function playerFlash()
  340. {
  341.    var _loc1_ = TimerInst.getTime();
  342.    if(_loc1_ - flashTime < INVINCIBLE_TIME)
  343.    {
  344.       if(playerInst._alpha == 100)
  345.       {
  346.          playerInst._alpha = 25;
  347.       }
  348.       else
  349.       {
  350.          playerInst._alpha = 100;
  351.       }
  352.    }
  353.    else
  354.    {
  355.       playerInst._alpha = 100;
  356.       playerInvincible = false;
  357.    }
  358. }
  359. function fireBullet()
  360. {
  361.    var _loc1_ = this;
  362.    var _loc2_ = _global;
  363.    point = new Object();
  364.    point.x = playerInst.playerAnimsInst.m1._x;
  365.    point.y = playerInst.playerAnimsInst.m1._y;
  366.    playerInst.playerAnimsInst.localToGlobal(point);
  367.    if(playerInst.playerState != playerInst.PLAYER_CLIMBING && playerInst.playerState != playerInst.PLAYER_CLIMBIDLE)
  368.    {
  369.       switch(gunType)
  370.       {
  371.          case "ice":
  372.             playerInst.playerAnimsInst.playerInst.gunsInst.iceGunInst.gotoAndPlay(2);
  373.             _loc2_.sfxIceGun.start();
  374.             break;
  375.          case "fire":
  376.             playerInst.playerAnimsInst.playerInst.gunsInst.fireGunInst.gotoAndPlay(2);
  377.             _loc2_.sfxFireGun.start();
  378.             break;
  379.          case "spray":
  380.             playerInst.playerAnimsInst.playerInst.gunsInst.sprayGunInst.gotoAndPlay(2);
  381.             _loc2_.sfxSprayGun.start();
  382.       }
  383.       bulletsActive.push(bulletsFree.pop());
  384.       _loc1_[bulletsActive[bulletsActive.length - 1]].gotoAndStop(gunType);
  385.       _loc1_[bulletsActive[bulletsActive.length - 1]]._xscale = playerInst.dir * 100;
  386.       _loc1_[bulletsActive[bulletsActive.length - 1]]._visible = true;
  387.       _loc1_[bulletsActive[bulletsActive.length - 1]].dir = playerInst.dir;
  388.       _loc1_[bulletsActive[bulletsActive.length - 1]].isNew = true;
  389.       _loc1_[bulletsActive[bulletsActive.length - 1]]._x = point.x;
  390.       _loc1_[bulletsActive[bulletsActive.length - 1]]._y = point.y;
  391.    }
  392. }
  393. function removeBullet(bullet)
  394. {
  395.    var _loc1_ = bullet;
  396.    var _loc2_ = this;
  397.    _loc2_[bulletsActive[_loc1_]]._visible = false;
  398.    _loc2_[bulletsActive[_loc1_]]._xscale = 100;
  399.    _loc2_[bulletsActive[_loc1_]]._yscale = 100;
  400.    bulletsFree.push(bulletsActive.splice(_loc1_,1)[0]);
  401. }
  402. function updateBullets()
  403. {
  404.    var _loc2_ = this;
  405.    var _loc1_ = 0;
  406.    while(_loc1_ < bulletsActive.length)
  407.    {
  408.       _loc2_[bulletsActive[_loc1_]]._x += BULLET_SPEED * _loc2_[bulletsActive[_loc1_]].dir;
  409.       _loc2_[bulletsActive[_loc1_]].isNew = false;
  410.       _loc2_[bulletsActive[_loc1_]]._x -= xPos - xPosOld;
  411.       _loc2_[bulletsActive[_loc1_]]._y -= yPos - yPosOld;
  412.       if(!stageBoxInst.hitTest(_loc2_[bulletsActive[_loc1_]]))
  413.       {
  414.          removeBullet(_loc1_);
  415.       }
  416.       _loc1_ = _loc1_ + 1;
  417.    }
  418.    yPosOld = yPos;
  419.    xPosOld = xPos;
  420. }
  421. function cullLevelObjects()
  422. {
  423.    for(clip in levelObjectsInst)
  424.    {
  425.       if(stageBoxInst.hitTest(levelObjectsInst[clip]))
  426.       {
  427.          switch(levelObjectsInst[clip].id)
  428.          {
  429.             case ENEMY_ID:
  430.                if(levelObjectsInst[clip].active)
  431.                {
  432.                   levelObjectsInst[clip]._visible = true;
  433.                }
  434.                levelObjectsInst[clip].deathTimer = TimerInst.getTime();
  435.                break;
  436.             case SPAWNPOINT_ID:
  437.                if(!levelObjectsInst[clip]._visible && levelObjectsInst[clip].lives != 0)
  438.                {
  439.                   levelObjectsInst[clip].active = true;
  440.                   levelObjectsInst[clip]._alpha = 100;
  441.                   levelObjectsInst[clip].gotoAndPlay(1);
  442.                   levelObjectsInst[clip].interval = TimerInst.getTime();
  443.                }
  444.                if(levelObjectsInst[clip].lives != 0)
  445.                {
  446.                   levelObjectsInst[clip]._visible = true;
  447.                }
  448.          }
  449.       }
  450.       else
  451.       {
  452.          switch(levelObjectsInst[clip].id)
  453.          {
  454.             case ENEMY_ID:
  455.                if(TimerInst.getTime() - levelObjectsInst[clip].deathTimer > 5000)
  456.                {
  457.                   levelObjectsInst[clip]._visible = false;
  458.                   removeEnemy(levelObjectsInst[clip]._name);
  459.                }
  460.                break;
  461.             case SPAWNPOINT_ID:
  462.                levelObjectsInst[clip]._visible = false;
  463.                levelObjectsInst[clip].active = false;
  464.          }
  465.       }
  466.    }
  467. }
  468. function resetLevel()
  469. {
  470.    overlayInst.gotoAndPlay(1);
  471.    playerInst.initialDrop = true;
  472.    musicVol = 0;
  473.    _global.sfxIngameMusic.setVolume(musicVol);
  474.    _global.sfxIngameMusic.start(0,9999);
  475.    IntroductionBoxInst._visible = true;
  476.    switch(level)
  477.    {
  478.       case 1:
  479.          xPos = 0;
  480.          yPos = 1513;
  481.          stageBoxInst.gotoAndStop("level1");
  482.          levelObjectsInst.gotoAndStop("level1");
  483.          gunType = "ice";
  484.          SPAWN_POINTS = 6;
  485.          FOOD_ITEMS = 10;
  486.          LADDERS = 4;
  487.          break;
  488.       case 2:
  489.          xPos = 0;
  490.          yPos = 751;
  491.          stageBoxInst.gotoAndStop("level2");
  492.          levelObjectsInst.gotoAndStop("level2");
  493.          gunType = "spray";
  494.          SPAWN_POINTS = 6;
  495.          FOOD_ITEMS = 12;
  496.          LADDERS = 3;
  497.          break;
  498.       case 3:
  499.          xPos = 0;
  500.          yPos = 1904;
  501.          stageBoxInst.gotoAndStop("level3");
  502.          levelObjectsInst.gotoAndStop("level3");
  503.          gunType = "fire";
  504.          SPAWN_POINTS = 10;
  505.          FOOD_ITEMS = 14;
  506.          LADDERS = 11;
  507.    }
  508.    BlockScrollerInst1.clearBlocks();
  509.    BlockScrollerInst1.addBlocks(MAX_TILES);
  510.    var _loc1_ = 0;
  511.    while(_loc1_ < MAX_TILES)
  512.    {
  513.       BlockScrollerInst1["block" + _loc1_].levelInst._visible = false;
  514.       _loc1_ = _loc1_ + 1;
  515.    }
  516.    BlockScrollerInst1.MoveTo(xPos,yPos);
  517.    playerInst._x = 275;
  518.    playerInst._y = 332;
  519.    lives = 3;
  520.    HUDBoxInst.livesInst.gotoAndStop(1);
  521.    playerInst.playerActive = true;
  522.    playerInst._visible = true;
  523.    playerInst.resetPlayer();
  524.    playerInvincible = false;
  525.    flashTime = 0;
  526.    levelScore = 0;
  527.    foodCollected = 0;
  528.    foodSaved = 0;
  529.    var _loc2_ = enemiesActive.length;
  530.    _loc1_ = 0;
  531.    while(_loc1_ < _loc2_)
  532.    {
  533.       removeEnemy(enemiesActive[0]);
  534.       _loc1_ = _loc1_ + 1;
  535.    }
  536.    resetSpawnPoints();
  537.    _loc1_ = 0;
  538.    while(_loc1_ < FOOD_ITEMS)
  539.    {
  540.       levelObjectsInst["food" + _loc1_]._visible = true;
  541.       levelObjectsInst["food" + _loc1_].value = 1;
  542.       levelObjectsInst["food" + _loc1_].gotoAndStop("good");
  543.       _loc1_ = _loc1_ + 1;
  544.    }
  545.    quitMessageInst._visible = false;
  546.    gameOverInst._visible = false;
  547.    gameOverInst.gotoAndStop(1);
  548.    levelCompleteBoxInst._visible = false;
  549.    HUDBoxInst._visible = true;
  550.    if(gameMode == MODE_PLAYDEMO)
  551.    {
  552.       quitButtonInst._visible = false;
  553.       getReadyInst._visible = false;
  554.       getReadyInst.gotoAndPlay("go");
  555.    }
  556.    else
  557.    {
  558.       quitButtonInst.enabled = false;
  559.       quitButtonInst._visible = true;
  560.       getReadyInst._visible = true;
  561.       getReadyInst.gotoAndPlay(1);
  562.       gameState = STATE_GAME_BEGIN;
  563.    }
  564. }
  565. function pauseGame()
  566. {
  567.    quitButtonInst.enabled = false;
  568.    TimerInst.stop();
  569.    for(clip in levelObjectsInst)
  570.    {
  571.       switch(levelObjectsInst[clip].id)
  572.       {
  573.          case ENEMY_ID:
  574.             levelObjectsInst[clip].bacteriaAnimsInst.bacteriaInst.stop();
  575.             for(anim in levelObjectsInst[clip].bacteriaAnimsInst.bacteriaInst)
  576.             {
  577.                levelObjectsInst[clip].bacteriaAnimsInst.bacteriaInst[anim].stop();
  578.             }
  579.             break;
  580.          case SPAWNPOINT_ID:
  581.             if(levelObjectsInst[clip]._visible && levelObjectsInst[clip].lives != 0)
  582.             {
  583.                levelObjectsInst[clip].fliesInst.stop();
  584.                levelObjectsInst[clip].stop();
  585.             }
  586.             break;
  587.          default:
  588.             for(anim in levelObjectsInst[clip])
  589.             {
  590.                levelObjectsInst[clip][anim].stop();
  591.             }
  592.       }
  593.    }
  594.    playerInst.playerAnimsInst.playerInst.stop();
  595.    for(anim in playerInst.playerAnimsInst.playerInst)
  596.    {
  597.       if(playerInst.playerAnimsInst.playerInst[anim]._name != "gunsInst")
  598.       {
  599.          playerInst.playerAnimsInst.playerInst[anim].stop();
  600.       }
  601.    }
  602. }
  603. function resumeGame()
  604. {
  605.    quitButtonInst.enabled = true;
  606.    TimerInst.start();
  607.    for(clip in levelObjectsInst)
  608.    {
  609.       switch(levelObjectsInst[clip].id)
  610.       {
  611.          case ENEMY_ID:
  612.             levelObjectsInst[clip].bacteriaAnimsInst.bacteriaInst.play();
  613.             for(anim in levelObjectsInst[clip].bacteriaAnimsInst.bacteriaInst)
  614.             {
  615.                levelObjectsInst[clip].bacteriaAnimsInst.bacteriaInst[anim].play();
  616.             }
  617.             break;
  618.          case SPAWNPOINT_ID:
  619.             if(levelObjectsInst[clip]._visible && levelObjectsInst[clip].active && levelObjectsInst[clip].lives > 0)
  620.             {
  621.                levelObjectsInst[clip].fliesInst.play();
  622.                levelObjectsInst[clip].play();
  623.             }
  624.             break;
  625.          default:
  626.             for(anim in levelObjectsInst[clip])
  627.             {
  628.                levelObjectsInst[clip][anim].play();
  629.             }
  630.       }
  631.    }
  632.    playerInst.playerAnimsInst.playerInst.play();
  633.    for(anim in playerInst.playerAnimsInst.playerInst)
  634.    {
  635.       if(playerInst.playerAnimsInst.playerInst[anim]._name != "gunsInst")
  636.       {
  637.          playerInst.playerAnimsInst.playerInst[anim].play();
  638.       }
  639.    }
  640. }
  641. function quitDemo()
  642. {
  643.    _global.sfxIngameMusic.stop();
  644.    gotoAndStop("Title Screen");
  645.    play();
  646. }
  647. stop();
  648. TimerInst._visible = false;
  649. KEYDOWN_JUMP = 32;
  650. KEYDOWN_SHOOT = 16;
  651. KEYDOWN_DOWN = 8;
  652. KEYDOWN_UP = 4;
  653. KEYDOWN_RIGHT = 2;
  654. KEYDOWN_LEFT = 1;
  655. frameCount = 0;
  656. averageFPS = 0;
  657. totalFPS = 0;
  658. numberOfFrames = 1;
  659. demoKey = 0;
  660. demoMoving = new Array(0,0,0,0,0,0,2,2,2,2,34,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,34,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,34,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,2,2,2,34,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,34,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,34,2,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0,33,1,1,1,1,1,1,1,1,1);
  661. demoShooting = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
  662. keysRecorded = 0;
  663. shotRecorded = 0;
  664. Mouse.removeListener(mouseListener);
  665. exitDemoButtonInst.onRelease = function()
  666. {
  667.    if(gameMode == MODE_PLAYDEMO)
  668.    {
  669.       quitDemo();
  670.    }
  671. };
  672. scoreMode = 1;
  673. currentScore = 0;
  674. sendToFriendMode = 1;
  675. ENEMY_ID = 0;
  676. SPAWNPOINT_ID = 1;
  677. MAX_BULLETS = 10;
  678. BULLET_SPEED = 20;
  679. INVINCIBLE_TIME = 3000;
  680. STATE_GAME_BEGIN = 0;
  681. STATE_GAME_RUNNING = 1;
  682. STATE_LEVEL_COMPLETE = 2;
  683. STATE_GAME_OVER = 3;
  684. STATE_PAUSED = 4;
  685. MAX_ENEMIES = 4;
  686. MAX_TILES = 25;
  687. if(gameMode == MODE_PLAYDEMO || gameMode == MODE_RECORDDEMO)
  688. {
  689.    level = 2;
  690.    DemoTextInst._visible = true;
  691.    exitDemoButtonInst._visible = true;
  692. }
  693. else
  694. {
  695.    level = 1;
  696.    DemoTextInst._visible = false;
  697.    exitDemoButtonInst._visible = false;
  698. }
  699. resetLevel();
  700. var bulletsFree = new Array();
  701. var bulletsActive = new Array();
  702. var i = 1;
  703. while(i <= MAX_BULLETS)
  704. {
  705.    attachMovie("allBullets","bullet" + i,200 + i);
  706.    this["bullet" + i]._visible = false;
  707.    bulletsFree.push(String("bullet" + i));
  708.    i++;
  709. }
  710. levelObjectsInst.attachMovie("bacteriaA","enemy1",101);
  711. levelObjectsInst.attachMovie("bacteriaB","enemy2",102);
  712. levelObjectsInst.attachMovie("bacteriaC","enemy3",103);
  713. levelObjectsInst.attachMovie("bacteriaA","enemy4",104);
  714. var i = 1;
  715. while(i <= MAX_ENEMIES)
  716. {
  717.    levelObjectsInst["enemy" + i]._visible = false;
  718.    i++;
  719. }
  720. var enemiesFree = new Array("enemy1","enemy2","enemy3","enemy4");
  721. var enemiesActive = new Array();
  722. onEnterFrame = function()
  723. {
  724.    var _loc2_ = this;
  725.    var _loc3_ = _global;
  726.    switch(gameMode)
  727.    {
  728.       case MODE_PLAYGAME:
  729.          if(musicVol < 100)
  730.          {
  731.             musicVol++;
  732.          }
  733.          _loc3_.sfxIngameMusic.setVolume(musicVol);
  734.          break;
  735.       case MODE_PLAYDEMO:
  736.          HUDBoxInst._visible = true;
  737.          if(musicVol < 100)
  738.          {
  739.             musicVol++;
  740.          }
  741.          _loc3_.sfxIngameMusic.setVolume(musicVol);
  742.          if(TimerInst.getTime() > 27750)
  743.          {
  744.             quitDemo();
  745.          }
  746.          nextKeyPress();
  747.          break;
  748.       case MODE_RECORDDEMO:
  749.          getKeyPresses();
  750.    }
  751.    switch(gameState)
  752.    {
  753.       case STATE_PAUSED:
  754.          break;
  755.       case STATE_GAME_BEGIN:
  756.          HUDBoxInst.food.text = foodCollected + " / " + FOOD_ITEMS;
  757.          BlockScrollerInst1.MoveTo(xPos,yPos);
  758.          levelObjectsInst._x = - xPos;
  759.          levelObjectsInst._y = - yPos;
  760.          cullLevelObjects();
  761.          break;
  762.       case STATE_GAME_RUNNING:
  763.          if(!fpsInfoSent)
  764.          {
  765.             getAverageFramerate();
  766.          }
  767.          updateEnemies();
  768.          updateSpawnPoints();
  769.          updateBullets();
  770.          playerInst.update();
  771.          if(playerInvincible)
  772.          {
  773.             playerFlash();
  774.          }
  775.          checkFoodCollisions();
  776.          HUDBoxInst.food.text = foodCollected + " / " + FOOD_ITEMS;
  777.          BlockScrollerInst1.MoveTo(xPos,yPos);
  778.          levelObjectsInst._x = - xPos;
  779.          levelObjectsInst._y = - yPos;
  780.          cullLevelObjects();
  781.          if(!playerInst.playerActive && foodCollected < FOOD_ITEMS && playerInst._y > 2000)
  782.          {
  783.             currentScore += foodSaved * 1000;
  784.             _quality = "HIGH";
  785.             gameState = STATE_GAME_OVER;
  786.          }
  787.          if(yPos > 2000)
  788.          {
  789.             currentScore += foodSaved * 1000;
  790.             _quality = "HIGH";
  791.             gameState = STATE_GAME_OVER;
  792.          }
  793.          if(foodCollected == FOOD_ITEMS)
  794.          {
  795.             timeBonus = int((120000 - TimerInst.getTime()) / 60) * 10;
  796.             if(timeBonus < 1000)
  797.             {
  798.                timeBonus = 0;
  799.             }
  800.             healthBonus = lives * 1000;
  801.             levelScore = foodSaved * 1000 + timeBonus + healthBonus;
  802.             _loc3_.sfxIngameMusic.stop();
  803.             _loc3_.sfxWinMusic.start(0,1);
  804.             currentScore += levelScore;
  805.             _quality = "HIGH";
  806.             gameState = STATE_LEVEL_COMPLETE;
  807.          }
  808.          break;
  809.       case STATE_LEVEL_COMPLETE:
  810.          var _loc1_ = 0;
  811.          while(_loc1_ < MAX_BULLETS + 1)
  812.          {
  813.             _loc2_["bullet" + _loc1_]._visible = false;
  814.             _loc1_ = _loc1_ + 1;
  815.          }
  816.          HUDBoxInst._visible = false;
  817.          quitButtonInst._visible = false;
  818.          levelCompleteBoxInst.foodSaved.text = foodSaved * 1000;
  819.          levelCompleteBoxInst.timeBonus.text = timeBonus;
  820.          levelCompleteBoxInst.healthBonus.text = healthBonus;
  821.          levelCompleteBoxInst.totalScore.text = levelScore;
  822.          levelCompleteBoxInst._visible = true;
  823.          playerInst.playerActive = false;
  824.          playerInst._visible = false;
  825.          updateEnemies();
  826.          break;
  827.       case STATE_GAME_OVER:
  828.          _loc1_ = 0;
  829.          while(_loc1_ < MAX_BULLETS + 1)
  830.          {
  831.             _loc2_["bullet" + _loc1_]._visible = false;
  832.             _loc1_ = _loc1_ + 1;
  833.          }
  834.          HUDBoxInst._visible = false;
  835.          quitButtonInst._visible = false;
  836.          gameOverInst.score.text = currentScore;
  837.          gameOverInst._visible = true;
  838.          levelCompleteBoxInst._visible = false;
  839.          updateEnemies();
  840.    }
  841. };
  842.